# coding=utf-8
"""
Created on 2018年08月29日
"""
from util_base.ufo_decorators import processor
from common_base.cmd import CMD
from processor_base.base_processor import BaseProcessor
from util_base.exception import ParamException, UFOException as E
from common_base.errors import AliveError
import json


@processor(CMD.CMD_ALIVE_SAVE_USER_FEEDBACK_INFO, internal_access=True)
class SaveUserFeedbackInfo(BaseProcessor):
    """
    SaveUserFeedbackInfo
    """
    
    TAG = 'SaveUserFeedbackInfo'
    
    def __init__(self, handler):
        """
        Constructor
        """
        BaseProcessor.__init__(self, handler)

    def process(self):
        """
        process protocol
        """
        userid = self.alive_cmsdb.get_userid_by_userkey(self.user_key)
        if not userid:
            raise E(AliveError.ERROR_USER_DOES_NOT_EXIST)

        # 保存用户反馈信息
        image_urls = json.dumps(self.image_list)
        self.alive_cmsdb.save_user_feedback_info(userid, self.content, self.contact, image_urls, self.NTIME)

        return dict()

    def _verify_params(self):
        """
        重写父类方法, 作参数校验
        """
        self.content = self.params.get('content')
        if not self.content:
            raise ParamException('content')

        self.contact = self.params.get('contact', '')

        self.image_list = self.params.get('imageList', list())